from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# from routes.dialogue_groups import router as dialogue_groups_router
from routes.dialogue import router as dialogue_router
from routes.auth import router as auth_router
from db import init_db


# 初始化数据库
init_db()

app = FastAPI()

# 配置 CORS
origins = [
    '*'
    # "https://your-frontend-domain.com",  # 允许的前端域名
    # "https://another-allowed-domain.com",  # 可以添加多个域名
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,  # 允许的来源
    allow_credentials=True,  # 允许发送 Cookie
    allow_methods=["GET", "POST", "PUT", "DELETE"],  # 允许的方法
    allow_headers=["*"],  # 允许的请求头
)

# Include routers
# app.include_router(dialogue_groups_router)
app.include_router(dialogue_router)
app.include_router(auth_router)
